﻿// Decompiled with JetBrains decompiler
// Type: TaleWorlds.CampaignSystem.LogEntries.MercenaryClanChangedKingdomLogEntry
// Assembly: TaleWorlds.CampaignSystem, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null
// MVID: E85F8C15-4DF6-4E9C-A58A-29177E40D07A
// Assembly location: D:\steam\steamapps\common\Mount & Blade II Bannerlord\bin\Win64_Shipping_Client\TaleWorlds.CampaignSystem.dll

using System.Collections.Generic;
using TaleWorlds.Core;
using TaleWorlds.Localization;
using TaleWorlds.SaveSystem;

#nullable disable
namespace TaleWorlds.CampaignSystem.LogEntries
{
  public class MercenaryClanChangedKingdomLogEntry : LogEntry, IChatNotification, IWarLog
  {
    [SaveableField(250)]
    public readonly Clan Clan;
    [SaveableField(251)]
    public readonly Kingdom OldKingdom;
    [SaveableField(252)]
    public readonly Kingdom NewKingdom;

    internal static void AutoGeneratedStaticCollectObjectsMercenaryClanChangedKingdomLogEntry(
      object o,
      List<object> collectedObjects)
    {
      ((LogEntry) o).AutoGeneratedInstanceCollectObjects(collectedObjects);
    }

    protected override void AutoGeneratedInstanceCollectObjects(List<object> collectedObjects)
    {
      base.AutoGeneratedInstanceCollectObjects(collectedObjects);
      collectedObjects.Add((object) this.Clan);
      collectedObjects.Add((object) this.OldKingdom);
      collectedObjects.Add((object) this.NewKingdom);
    }

    internal static object AutoGeneratedGetMemberValueClan(object o)
    {
      return (object) ((MercenaryClanChangedKingdomLogEntry) o).Clan;
    }

    internal static object AutoGeneratedGetMemberValueOldKingdom(object o)
    {
      return (object) ((MercenaryClanChangedKingdomLogEntry) o).OldKingdom;
    }

    internal static object AutoGeneratedGetMemberValueNewKingdom(object o)
    {
      return (object) ((MercenaryClanChangedKingdomLogEntry) o).NewKingdom;
    }

    public bool IsVisibleNotification => true;

    public MercenaryClanChangedKingdomLogEntry(Clan clan, Kingdom oldKingdom, Kingdom newKingdom)
    {
      this.Clan = clan;
      this.OldKingdom = oldKingdom;
      this.NewKingdom = newKingdom;
    }

    public bool IsRelatedToWar(StanceLink stance, out IFaction effector, out IFaction effected)
    {
      IFaction faction1 = stance.Faction1;
      IFaction faction2 = stance.Faction2;
      effector = this.NewKingdom?.MapFaction;
      effected = this.OldKingdom?.MapFaction;
      return this.NewKingdom == faction2 || this.NewKingdom == faction1;
    }

    public override string ToString() => this.GetNotificationText().ToString();

    public override ChatNotificationType NotificationType
    {
      get => this.MilitaryNotification((IFaction) this.NewKingdom, (IFaction) this.OldKingdom);
    }

    public TextObject GetNotificationText()
    {
      if (this.OldKingdom == null && this.NewKingdom != null)
      {
        TextObject text = GameTexts.FindText("str_notification_mercenary_contract");
        text.SetTextVariable("CLAN", this.Clan.Name);
        text.SetTextVariable("KINGDOM", this.NewKingdom.InformalName);
        return text;
      }
      if (this.OldKingdom != null && this.NewKingdom == null)
      {
        TextObject text = GameTexts.FindText("str_notification_mercenary_contract_end");
        text.SetTextVariable("CLAN", this.Clan.Name);
        text.SetTextVariable("KINGDOM", this.OldKingdom.InformalName);
        return text;
      }
      if (this.OldKingdom == null || this.NewKingdom == null)
        return TextObject.Empty;
      TextObject text1 = GameTexts.FindText("str_notification_mercenary_contract");
      text1.SetTextVariable("CLAN", this.Clan.Name);
      text1.SetTextVariable("KINGDOM", this.NewKingdom.InformalName);
      return text1;
    }
  }
}
